package com.example.textviewactivity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.textviewactivity.pojo.User;

public class LoginActivity extends AppCompatActivity {
    EditText ed_name,ed_pwd;
    TextView logon;
    CheckBox save;
    User user1=new User();
    private static final String TAG = "LoginActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        logon=findViewById(R.id.logon);
        ed_name=findViewById(R.id.ed_name);
        ed_pwd=findViewById(R.id.ed_pwd);
        save=findViewById(R.id.save);
        logon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(LoginActivity.this,LogonActivity.class);
                startActivityForResult(intent,200);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==200){
            User user = (User) data.getSerializableExtra("user");
            ed_name.setText(user.getName()+"");
            ed_pwd.setText(user.getPassword()+"");
            user1.setName(user.getName());
            user1.setPhone(user.getPhone());
            user1.setPassword(user.getPassword());
            user1.setHobby(user.getHobby());
            user1.setSex(user.getSex());
            Log.d(TAG, "onActivityResult: "+user);
        }
    }

    public void login(View view){
        if (save.isChecked()){
            Intent intent=new Intent(LoginActivity.this,LoginSuccessActivity.class);
            intent.putExtra("user",user1);
            startActivity(intent);
        }else{
            Toast.makeText(LoginActivity.this, "勾选记住密码才能登陆", Toast.LENGTH_SHORT).show();
        }
    }
}
